#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\DCT.h>



static void *storeFromStruct;

static int recordNum;
void registerDCT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadDCTRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerDCT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(DCT_FILENAME, SIZE_DCT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreDCTRecFromStruct(void *vdStruct)
{
	registerDCT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetDCTRec(), vdStruct, SIZE_DCT_REC);

}

void vdCopyDCTRecFromStruct(void *vdStruct)
{
	registerDCT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetDCTRec(), SIZE_DCT_REC);

}

int	inSaveDCTRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerDCT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(DCT_FILENAME, SIZE_DCT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateDCTRecFromStruct (void *vdStruct)
{
	int inRet;

	registerDCT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(DCT_FILENAME, SIZE_DCT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

char* szGetPINKeyFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetPINKey();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((DCT_REC*)vdStruct)->szPINKey;
}

void vdSetPINKeyFromStruct(const char* szPINKey, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetPINKey(szPINKey);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((DCT_REC*)vdStruct)->szPINKey, szPINKey, sizeof(((DCT_REC*)NULL)->szPINKey)-1);
}

short inGetMinPINDigitFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetMinPINDigit();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((DCT_REC*)vdStruct)->inMinPINDigit;
}

void vdSetMinPINDigitFromStruct(short inMinPINDigit, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMinPINDigit(inMinPINDigit);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((DCT_REC*)vdStruct)->inMinPINDigit = inMinPINDigit;
}

short inGetMaxPINDigitFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetMaxPINDigit();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((DCT_REC*)vdStruct)->inMaxPINDigit;
}

void vdSetMaxPINDigitFromStruct(short inMaxPINDigit, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMaxPINDigit(inMaxPINDigit);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((DCT_REC*)vdStruct)->inMaxPINDigit = inMaxPINDigit;
}

char chGetMasterKeyAddressFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return chGetMasterKeyAddress();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((DCT_REC*)vdStruct)->chMasterKeyAddress;
}

void vdSetMasterKeyAddressFromStruct(char chMasterKeyAddress, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMasterKeyAddress(chMasterKeyAddress);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((DCT_REC*)vdStruct)->chMasterKeyAddress = chMasterKeyAddress;
}

char* szGetKSIFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetKSI();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((DCT_REC*)vdStruct)->szKSI;
}

void vdSetKSIFromStruct(const char* szKSI, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetKSI(szKSI);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((DCT_REC*)vdStruct)->szKSI, szKSI, sizeof(((DCT_REC*)NULL)->szKSI)-1);
}

